package com.farmproduct.controller;

import com.farmproduct.pojo.BackMes;
import com.farmproduct.service.BackMesService;
import com.farmproduct.tools.SnowflakeIdWorker;
import com.farmproduct.vo.ResultVO;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/backmes")
@CrossOrigin
public class BackMesController {
    @Autowired
    private BackMesService backMesService;


    //    根据用户添加产品
    @RequestMapping(value = "/add")
    public ResultVO addBackMesByUid(@RequestBody BackMes backMes){
        backMes.setBid(SnowflakeIdWorker.generateId().toString());
        if (backMesService.addBackMes(backMes)){
            return new ResultVO(200,"success",0,null);
        }
        return new ResultVO();
    }

    //    根据用户获取
    @RequestMapping(value = "/getno/{uid}")
    public ResultVO getBackMesByUidNo(@PathVariable String  uid){
        List<BackMes> backMesByUid = backMesService.getBackMesByUidNo(uid);
        if (backMesByUid!=null){
            return new ResultVO(200,"success",0,backMesByUid);
        }
        return new ResultVO();
    }
    //    根据用户获取
    @RequestMapping(value = "/getyes/{uid}")
    public ResultVO getBackMesByUidYes(@PathVariable String  uid){
        List<BackMes> backMesByUid = backMesService.getBackMesByUidYes(uid);
        if (backMesByUid!=null){
            return new ResultVO(200,"success",0,backMesByUid);
        }
        return new ResultVO();
    }

    //    删除产品
    @RequestMapping(value = "/del")
    public ResultVO delBackMes(@RequestBody BackMes backMes){
        if (backMesService.delBackMes(backMes)){
            return new ResultVO(200,"success",0,null);
        }
        return new ResultVO();
    }
    //    删除产品
    @RequestMapping(value = "/delbackmeslist")
    public ResultVO delBackMesList(@RequestBody List<BackMes> backMesList){
        if (backMesService.delBackMesList(backMesList)){
            return new ResultVO(200,"success",0,null);
        }
        return new ResultVO();
    }

    @RequestMapping(value = "/updatebackmesliststatus")
    public ResultVO updateBackMesList(@RequestBody List<BackMes> backMesList){
        if (backMesService.updateBackMesList(backMesList)){
            return new ResultVO(200,"success",0,null);
        }
        return new ResultVO();
    }
    @RequestMapping(value = "/updatestatus")
    public ResultVO updateBackMesStatus(@RequestBody BackMes backMes){
        if (backMesService.updateBackMesStatus(backMes)){
            return new ResultVO(200,"success",0,null);
        }
        return new ResultVO();
    }
}
